package pub.lichao.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
public class StartController {
    @Autowired
    protected JdbcTemplate jdbcTemplate;

    /**
     * 查询用户数据
     * @param model
     * @return
     */
    @RequestMapping(value = "/")
    public String index(Model model) {
        //正常境况下SQL应该写在dao层，本项目简单起见写在这里了
        String sql ="SELECT user_name,phone FROM ex_user LIMIT 10;";
        List<Map<String, Object>> userlist = jdbcTemplate.queryForList(sql);

        model.addAttribute("var", "hello world");
        model.addAttribute("userlist", userlist);
        return "index";
    }
}
